package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	fp1, err := os.Open("cp6_file/write.txt")
	if err != nil {
		fmt.Println(err)
	}
	defer fp1.Close()

	fp2, err := os.OpenFile("cp6_file/write_copy.txt", os.O_CREATE|os.O_WRONLY, 0755)
	if err != nil {
		fmt.Println(err)
	}
	defer fp2.Close()

	len, err := io.Copy(fp2, fp1) //把fp2的文件内容复制到fp1
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("复制成功，复制字节数：", len)
	}

}
